﻿Imports Microsoft.Office.Interop
Public Class fClientes
    Dim daCliente As lbGlobalcom.dsTerceroTableAdapters.TER_CLIENTESTableAdapter
    Dim daTipoCliente As lbGlobalcom.dsTerceroTableAdapters.TER_TIPOCLIENTESTableAdapter
    Dim daFormaPago As lbGlobalcom.dsCarteraTableAdapters.CAR_FORMASPAGOTableAdapter
    Dim daDatosTablas As lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
    Dim daVend As lbGlobalcom.dsConsultasGlobalTableAdapters.GLO_LISTAVENDEDORESTableAdapter
    Dim daBod As lbGlobalcom.dsInventariosTableAdapters.INV_BODEGASTableAdapter
    Dim daCan As lbGlobalcom.dsFacturacionTableAdapters.FAC_CANALESTableAdapter
    Dim daListaPrecios As lbGlobalcom.dsProductosTableAdapters.PRO_ENCALISTAPRECIOSTableAdapter
    Private Sub fClientes_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AddHandler Me.SalvaTerecero, AddressOf Salvar
        AddHandler Me.BuscaTercero, AddressOf BuscaCliente
        AddHandler Me.EliminaTercero, AddressOf EliminaCliente
        AddHandler Me.ExporToExcel, AddressOf ExportCliToExcel
        MyBase.MustraMsjSalva = False
        daCliente = New lbGlobalcom.dsTerceroTableAdapters.TER_CLIENTESTableAdapter
        daTipoCliente = New lbGlobalcom.dsTerceroTableAdapters.TER_TIPOCLIENTESTableAdapter
        daFormaPago = New lbGlobalcom.dsCarteraTableAdapters.CAR_FORMASPAGOTableAdapter
        daDatosTablas = New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
        daVend = New lbGlobalcom.dsConsultasGlobalTableAdapters.GLO_LISTAVENDEDORESTableAdapter
        daBod = New lbGlobalcom.dsInventariosTableAdapters.INV_BODEGASTableAdapter
        daCan = New lbGlobalcom.dsFacturacionTableAdapters.FAC_CANALESTableAdapter
        daListaPrecios = New lbGlobalcom.dsProductosTableAdapters.PRO_ENCALISTAPRECIOSTableAdapter
        Try
            daTipoCliente.Fill(DsTercero.TER_TIPOCLIENTES)
            daFormaPago.Fill(DsCartera.CAR_FORMASPAGO)
            daDatosTablas.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "es")
            daVend.Fill(DsConsultasGlobal.GLO_LISTAVENDEDORES)
            daBod.Fill(DsInventarios1.INV_BODEGAS)
            daCan.Fill(DsFacturacion.FAC_CANALES)
            daListaPrecios.Fill(DsProductos.PRO_ENCALISTAPRECIOS)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
    Private Sub ExportCliToExcel()
        Try
            Me.Cursor = Cursors.WaitCursor
            Dim cex As New lbGlobalcom.cExcel(lbGlobalcom.DatosTerceros.GetClientes())
            Dim m_Excel As Excel.Application
            m_Excel = cex.exportarExcel
            m_Excel.Visible = True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub
    Private Sub Salvar()
        Try
            TER_CLIENTESBindingSource.EndEdit()
            daCliente.Update(DsTercero.TER_CLIENTES)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
    Private Sub BuscaCliente(ByVal idTercero As String)
        Try
            daCliente.FillByIdCliente(DsTercero.TER_CLIENTES, idTercero)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
    Private Sub EliminaCliente()
        Try
            TER_CLIENTESBindingSource.Remove(TER_CLIENTESBindingSource.Current)
            daCliente.Update(DsTercero.TER_CLIENTES)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub TER_CLIENTESDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles TER_CLIENTESDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub
End Class
